package de.stefanocke.roo.wicket.base;

import java.util.logging.Logger;

import org.springframework.roo.model.JavaType;
import org.springframework.roo.support.logging.HandlerUtils;

import de.stefanocke.roo.wicket.model.JavaTypeMetadataDetails;
import de.stefanocke.roo.xtend.ItdBuilder;

public abstract class ModelClassAwareItdMetadataBase<AV> extends ItdMetadataBase<AV> implements
		ModelClassAwareMetadata, AutoWireSettings {

	protected static final Logger logger = HandlerUtils.getLogger(ModelClassAwareItdMetadataBase.class);

	private JavaTypeMetadataDetails modelClassTypeDetails;

	public ModelClassAwareItdMetadataBase(ModelClassAwareMetadataCreationParams<AV> cmcp, ItdBuilder itdBuilder) {
		super(cmcp.getCommonMetadataCreationParams(), itdBuilder);

		this.modelClassTypeDetails = cmcp.getModelClassTypeDetails();
		

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.stefanocke.roo.wicket.base.WicketItdMetadata#getModelClass()
	 */
	@Override
	public JavaType getModelClass() {
		if ( modelClassTypeDetails != null) {
			return modelClassTypeDetails.getJavaType();
		} else {
			return null;
		}
	}
	
	

	public JavaTypeMetadataDetails getModelClassTypeDetails() {
		return modelClassTypeDetails;
	}

	public void setModelClassTypeDetails(JavaTypeMetadataDetails modelClassTypeDetails) {
		this.modelClassTypeDetails = modelClassTypeDetails;
	}

	@Override
	public boolean isAutowireCandidate() {

		if (getAnnotationValues() instanceof AutoWireSettings) {
			return ((AutoWireSettings) getAnnotationValues()).isAutowireCandidate();
		}
		return true;
	}
	
	

}